package com.zhuss.order.processor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.vo.order.order.DetailOrderVo;
import com.zhuss.enums.OrderStatus;
import com.zhuss.enums.StartStopEnum;
import com.zhuss.exception.DzcxException;


@Component("orderCheck")
public class OrderCheck {
	
	@Autowired
	@Qualifier("orderRead")
	private OrderRead orderRead;
	
	public boolean checkUnuse(DetailOrderVo order) throws DzcxException {
		if (OrderStatus.未支付.sameKey(order.getStatus()) || OrderStatus.已提交支付.sameKey(order.getStatus())) {
			return true;
		}
		return false;
	}
	
	public boolean checkCancel(DetailOrderVo order) throws DzcxException {
		if (OrderStatus.未支付.sameKey(order.getStatus())) {
			return true;
		}
		return false;
	}
	
	public boolean checkPay(DetailOrderVo order) throws DzcxException {
		if (OrderStatus.未支付.sameKey(order.getStatus()) || OrderStatus.已提交支付.sameKey(order.getStatus())) {
			return true;
		}
		return false;
	}
	
	public Boolean checkBelongUser(DetailOrderVo order, Long userId) throws DzcxException {
		if (userId.equals(order.getCreatorId())) {
			return true;
		}
		return false;
	}
	
	public boolean checkStart(Long orderId) throws DzcxException {
		DetailOrderVo order = ((DetailOrderVo) orderRead.detail(orderId));
		if (StartStopEnum.停用.sameKey(order.getStatus())) {
			return true;
		}
		return false;
	}
	
	public boolean checkStop(Long orderId) throws DzcxException {
		DetailOrderVo order = ((DetailOrderVo) orderRead.detail(orderId));
		if (StartStopEnum.启用.sameKey(order.getStatus())) {
			return true;
		}
		return false;
	}
	
}
